#include <iostream>
#include "concrete_visitor.h"
#include "object_structure.h"
#include"concrete_element.h"
#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if(p){delete(p); (p)=NULL;} }
#endif

int main()
{
    City *city = new City();
    // 景点 - 钟楼、兵马俑
    IPlace *bellTower = new BellTower("Bell Tower");
    IPlace *warriors = new TerracottaWarriors("TerracottaWarriors");
    IPlace *center = new Center("Center");

    // 访问者 - 游客、清洁工
    IVisitor *tourist = new Tourist("Li Tourist");
    IVisitor *tourist2 = new Tourist("May Tourist");
    IVisitor *cleaner = new Cleaner("Zhang Cleaner");

    // 添加景点
    city->Attach(bellTower);
    city->Attach(warriors);
    city->Attach(center);

    // 接受访问
    city->Accept(tourist);
    city->Accept(cleaner);
    city->Accept(tourist2);

    cout<<"...................................."<<endl;
    //删除景点
    city->Detach(bellTower);
     // 接受访问
    city->Accept(tourist);
    city->Accept(cleaner);
    city->Accept(tourist2);

    SAFE_DELETE(cleaner);
    SAFE_DELETE(tourist);
    SAFE_DELETE(tourist2);
    SAFE_DELETE(warriors);
    SAFE_DELETE(bellTower);
    SAFE_DELETE(center);
    SAFE_DELETE(city);

    getchar();


    return 0;
}
